import { IPSAppCounterRef } from '../../app/control/ipsapp-counter-ref';
import { IPSAppViewUIAction } from '../../app/view/ipsapp-view-uiaction';
import { IPSDECMUIActionItem } from './ipsdecmuiaction-item';
import { IPSDETBUIActionItem } from './ipsdetbuiaction-item';
import { IPSDEToolbarItem } from './ipsdetoolbar-item';
import { PSDEToolbarItemImpl } from './psdetoolbar-item-impl';
import { IPSLanguageRes } from '../../res/ipslanguage-res';
import { IPSSysImage } from '../../res/ipssys-image';
import { IPSUIAction } from '../../view/ipsuiaction';

export class PSDETBUIActionItemImpl extends PSDEToolbarItemImpl implements IPSDETBUIActionItem, IPSDECMUIActionItem {
  get actionLevel(): 50 | 100 | 200 | 250 {
    return this.M.actionLevel != null ? this.M.actionLevel : 100;
  }

  protected cappslanguageres: IPSLanguageRes | null = null;

  getCapPSLanguageRes(): IPSLanguageRes | null {
    if (this.cappslanguageres != null) return this.cappslanguageres;
    const value = this.M.getCapPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.cappslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getCapPSLanguageRes') as IPSLanguageRes;
    return this.cappslanguageres;
  }

  get capPSLanguageRes(): IPSLanguageRes | null {
    return this.getCapPSLanguageRes();
  }

  getCapPSLanguageResMust(): IPSLanguageRes {
    const value = this.getCapPSLanguageRes();
    if (value == null) {
      throw new Error('未指定标题语言资源');
    }
    return value;
  }

  get groupExtractMode(): 'ITEM' | 'ITEMS' {
    return this.M.groupExtractMode;
  }

  get noPrivDisplayMode(): 1 | 2 | 6 {
    return this.M.noPrivDisplayMode;
  }

  protected psappcounterref: IPSAppCounterRef | null = null;

  getPSAppCounterRef(): IPSAppCounterRef | null {
    if (this.psappcounterref != null) return this.psappcounterref;
    const value = this.M.getPSAppCounterRef;
    if (value == null) {
      return null;
    }
    this.psappcounterref = this.getPSModel4('app.control.IPSAppCounterRef', value, 'getPSAppCounterRef') as IPSAppCounterRef;
    return this.psappcounterref;
  }

  get psAppCounterRef(): IPSAppCounterRef | null {
    return this.getPSAppCounterRef();
  }

  getPSAppCounterRefMust(): IPSAppCounterRef {
    const value = this.getPSAppCounterRef();
    if (value == null) {
      throw new Error('未指定应用计数器引用');
    }
    return value;
  }

  protected psappviewuiaction: IPSAppViewUIAction | null = null;

  getPSAppViewUIAction(): IPSAppViewUIAction | null {
    if (this.psappviewuiaction != null) return this.psappviewuiaction;
    const value = this.M.getPSAppViewUIAction;
    if (value == null) {
      return null;
    }
    this.psappviewuiaction = this.getPSModel4('app.view.IPSAppViewUIAction', value, 'getPSAppViewUIAction') as IPSAppViewUIAction;
    return this.psappviewuiaction;
  }

  get psAppViewUIAction(): IPSAppViewUIAction | null {
    return this.getPSAppViewUIAction();
  }

  getPSAppViewUIActionMust(): IPSAppViewUIAction {
    const value = this.getPSAppViewUIAction();
    if (value == null) {
      throw new Error('未指定应用视图界面行为');
    }
    return value;
  }

  protected psdetoolbaritems: IPSDEToolbarItem[] | null = null;

  getPSDEToolbarItems(): IPSDEToolbarItem[] | null {
    if (this.psdetoolbaritems == null) {
      this.psdetoolbaritems = this.fillChildListModel(this.M.getPSDEToolbarItems, 'control.toolbar.IPSDEToolbarItem') as IPSDEToolbarItem[];
    }
    return this.psdetoolbaritems;
  }

  get psDEToolbarItems(): IPSDEToolbarItem[] | null {
    return this.getPSDEToolbarItems();
  }

  findPSDEToolbarItem(objKey: any): IPSDEToolbarItem | null {
    return this.getPSModel5('control.toolbar.IPSDEToolbarItem', this.getPSDEToolbarItems(), objKey) as IPSDEToolbarItem;
  }

  protected pssysimage: IPSSysImage | null = null;

  getPSSysImage(): IPSSysImage | null {
    if (this.pssysimage != null) return this.pssysimage;
    const value = this.M.getPSSysImage;
    if (value == null) {
      return null;
    }
    this.pssysimage = this.getPSModel4('res.IPSSysImage', value, 'getPSSysImage') as IPSSysImage;
    return this.pssysimage;
  }

  get psSysImage(): IPSSysImage | null {
    return this.getPSSysImage();
  }

  getPSSysImageMust(): IPSSysImage {
    const value = this.getPSSysImage();
    if (value == null) {
      throw new Error('未指定图标资源对象');
    }
    return value;
  }

  protected psuiaction: IPSUIAction | null = null;

  getPSUIAction(): IPSUIAction | null {
    if (this.psuiaction != null) return this.psuiaction;
    const value = this.M.getPSUIAction;
    if (value == null) {
      return null;
    }
    this.psuiaction = this.getPSModel4('view.IPSUIAction', value, 'getPSUIAction') as IPSUIAction;
    return this.psuiaction;
  }

  get psUIAction(): IPSUIAction | null {
    return this.getPSUIAction();
  }

  getPSUIActionMust(): IPSUIAction {
    const value = this.getPSUIAction();
    if (value == null) {
      throw new Error('未指定界面行为对象');
    }
    return value;
  }

  get tooltip(): string {
    return this.M.tooltip;
  }

  protected tooltippslanguageres: IPSLanguageRes | null = null;

  getTooltipPSLanguageRes(): IPSLanguageRes | null {
    if (this.tooltippslanguageres != null) return this.tooltippslanguageres;
    const value = this.M.getTooltipPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.tooltippslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getTooltipPSLanguageRes') as IPSLanguageRes;
    return this.tooltippslanguageres;
  }

  get tooltipPSLanguageRes(): IPSLanguageRes | null {
    return this.getTooltipPSLanguageRes();
  }

  getTooltipPSLanguageResMust(): IPSLanguageRes {
    const value = this.getTooltipPSLanguageRes();
    if (value == null) {
      throw new Error('未指定提示语言资源');
    }
    return value;
  }

  get uIActionParamJO(): IModel {
    return this.M.uIActionParamJO;
  }

  get uIActionTarget(): 'SINGLEDATA' | 'SINGLEKEY' | 'MULTIDATA' | 'MULTIKEY' | 'NONE' {
    return this.M.uIActionTarget;
  }

  get xDataControlName(): string {
    return this.M.xDataControlName;
  }

  get enableToggleMode(): boolean {
    return this.M.enableToggleMode != null ? this.M.enableToggleMode : false;
  }

  get hiddenItem(): boolean {
    return this.M.hiddenItem != null ? this.M.hiddenItem : false;
  }

  get saveTargetFirst(): boolean {
    return this.M.saveTargetFirst != null ? this.M.saveTargetFirst : false;
  }

  get valid(): boolean {
    return this.M.valid != null ? this.M.valid : true;
  }

  get cls(): string {
    return 'PSDETBUIActionItemImpl';
  }

  instanceof(cls: string): boolean {
    if (
      cls == 'app.view.IPSAppViewUIAction' ||
      cls == 'app.view.IPSDEUIActionItem' ||
      cls == 'app.view.IPSUIActionItem' ||
      cls == 'app.view.IPSWFUIActionItem' ||
      cls == 'control.toolbar.IPSDECMUIActionItem' ||
      cls == 'control.toolbar.IPSDETBUIActionItem'
    )
      return true;
    return super.instanceof(cls);
  }
}
